package com.kc.config;

import com.kc.ExceptionHandler.ClintException;
import com.kc.ExceptionHandler.UndowException;
import com.kc.util.ResponesBean;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionCapture {

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(ClintException.class)
    public ResponesBean handle(ClintException e){
        return new ResponesBean(HttpStatus.BAD_REQUEST.value(),e.getMessage(),null);
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(Exception.class)
    public ResponesBean handle(Exception e){
        return new ResponesBean(HttpStatus.BAD_REQUEST.value(),e.getMessage(),null);
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(UndowException.class)
    public ResponesBean handle(UndowException e){
        return new ResponesBean(HttpStatus.BAD_REQUEST.value(),e.getMessage(),null);
    }
}
